package org.linlinjava.litemall.admin.service;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.linlinjava.litemall.db.domain.LitemallUser;
import org.linlinjava.litemall.db.service.LitemallUserService;
import org.linlinjava.litemall.db.service.LitemallUserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;

@Component
public class UserTokenHelper{
	@Autowired
	private LitemallUserTokenService userTokenService;
    @Autowired
    private LitemallUserService userService;
    
    
    public void updateUserToken(Integer shopId) {
    	List<LitemallUser> userList = userService.queryByShopId(shopId);
    	if(CollectionUtils.isEmpty(userList)) {
    		return;
    	}
    	List<Integer> userIdList = Lists.newArrayList();
    	for(LitemallUser user : userList) {
    		userIdList.add(user.getId());
    	}
    	userTokenService.updateByUserIds(userIdList);
    }
}
